<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流程名称" prop="processName">
        <el-input v-model="queryParams.processName" placeholder="请输入流程名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审批时间">
        <el-date-picker v-model="dateRange" style="width: 215px" size="small" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table stripe v-loading="loading" :data="finishedList" :show-header="false">
      <el-table-column align="left" prop="procDefName" min-width="200" show-overflow-tooltip>
        <template slot-scope="scope">
          <div class="placeholder ellipsis">{{ spliceTodoTitle(scope.row) }}</div>
          <div class="ellipsis">流程名称: {{ scope.row.procDefName }}</div>
        </template>
      </el-table-column>
      <el-table-column align="left" prop="taskName" show-overflow-tooltip min-width="130">
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <div class="ellipsis">已办节点: {{ scope.row.taskName }}</div>
        </template>
      </el-table-column>
      <el-table-column align="left" prop="createTime" width="215" show-overflow-tooltip>
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <div class="ellipsis">接收时间: {{ scope.row.createTime }}</div>
        </template>
      </el-table-column>
      <el-table-column align="left" prop="finishTime" width="215" show-overflow-tooltip>
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <div class="ellipsis">审批时间: {{ scope.row.finishTime }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" width="160" show-overflow-tooltip>
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleFlowRecord(scope.row)"
            v-hasPermi="['workflow:process:query']">流转记录</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleRevoke(scope.row)" v-hasPermi="['workflow:process:revoke']">撤回</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listFinishedProcess } from '@/api/workflow/process';
import { revokeProcess } from '@/api/workflow/finished';

export default {
  data () {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 已办任务列表数据
      finishedList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      src: '',
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        processName: null,
        projectName: null,
        category: null,
        key: null,
        tenantId: null,
        deployTime: null,
        derivedFrom: null,
        derivedFromRoot: null,
        parentDeploymentId: null,
        engineVersion: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created () {
    // this.getList();
  },
  methods: {
    /** 查询流程定义列表 */
    getList () {
      this.loading = true;
      listFinishedProcess(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        this.finishedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    setIcon (val) {
      if (val) {
        return 'el-icon-check';
      } else {
        return 'el-icon-time';
      }
    },
    setColor (val) {
      if (val) {
        return '#2bc418';
      } else {
        return '#b3bdbb';
      }
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.dateRange = [];
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 流程流转记录 */
    handleFlowRecord (row) {
      this.$router.push({
        path: '/workflow/process/detail/' + row.procInsId,
        query: {
          definitionId: row.procDefId,
          deployId: row.deployId,
          taskId: row.taskId,
          finished: false
        }
      });
    },
    /** 撤回任务 */
    handleRevoke (row) {
      const params = {
        procInsId: row.procInsId,
        taskId: row.taskId
      };
      revokeProcess(params).then((res) => {
        this.$modal.msgSuccess(res.msg);
        this.getList();
      });
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        'workflow/process/finishedExport',
        {
          ...this.queryParams
        },
        `wf_finished_process_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.placeholder {
  font-weight: bold;
  font-size: 15px;
  height: 25px;
}
</style>